package com.kevin.util.tag;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;

import com.kevin.util.Function;
/**
 * 
  * @ClassName: ListFieldTag 
  * @Description: 将list里的值转换为list
  * @author 吕凯
  * @date 2012-11-23 上午11:14:41 
  *
 */
public class ListFieldTag  extends TagSupport{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1345464786L;
	private String var = null;
	private List<Object> list;
	private String field;
	
	

	@Override
	public int doEndTag() throws JspException {
		List<Object> fieldList = new ArrayList<Object>();
		for(Object obj:list){
			try {
				String value = Function.getValue(obj, field)+"";
				fieldList.add(value);
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		System.out.println("fieldlist=="+fieldList);
		pageContext.setAttribute(var, fieldList);
		return SKIP_BODY;
	}

	@Override
	public int doStartTag() throws JspException {
		// TODO Auto-generated method stub
		return EVAL_PAGE;
	}

	public String getVar() {
		return var;
	}

	public void setVar(String var) {
		this.var = var;
	}

	public List<Object> getList() {
		return list;
	}

	public void setList(List<Object> list) {
		this.list = list;
	}

	public String getField() {
		return field;
	}

	public void setField(String field) {
		this.field = field;
	}

	
	

}
